<!-- 投诉管理 -->
<template>
	<section>
		<!--列表-->
		<el-table :data="List" highlight-current-row v-loading="loading" @selection-change="selsChange" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
			<el-table-column prop="id" align="center" label="ID" width="60"></el-table-column>
			<el-table-column prop="problemType" align="center" label="投诉类型" :formatter="Type" width="100">
				<template slot-scope="scope">
					<div slot="reference" class="name-wrapper">
						<el-tag effect="dark" size="small" v-if="scope.row.problemType == '1'">商品</el-tag>
						<el-tag effect="dark" size="small" type="success" v-else-if="scope.row.problemType == '2'">订单</el-tag>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="realName" align="center" label="投诉人姓名"></el-table-column>
			<el-table-column prop="phone" align="center" label="投诉人手机号"></el-table-column>
			<el-table-column prop="problem" align="center" label="投诉项目">
				<template slot-scope="scope">
					<el-popover trigger="hover" placement="top">
						<p>投诉内容: {{ scope.row.problemContent }}</p>
						<div slot="reference" class="name-wrapper">
							<el-tag size="medium">{{ scope.row.problem}}</el-tag>
						</div>
					</el-popover>
				</template>
			</el-table-column>
			<el-table-column prop="goodsName" align="center" label="投诉商品名称"></el-table-column>
			<el-table-column prop="createTime" align="center" label="投诉时间"></el-table-column>
			<el-table-column label="操作" align="center" width="260">
				<template slot-scope="scope">
					<el-button type="success" size="small" icon="el-icon-view" @click='getsee(scope.$index, scope.row)'>查看</el-button>
					<el-button v-if="scope.row.disposeContent == ''" type="primary" size="small" @click="handleEdit(scope.$index, scope.row)" icon="el-icon-edit">处理投诉</el-button>
					<el-button v-else type="info" size="small" icon="el-icon-warning">处理完成</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--批量删除-->
		<el-col :span="24" class="toolbar">
			<el-pagination background layout="total,sizes,prev, pager, next,jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<!-- 投诉处理 -->
		<el-dialog title="投诉处理" :visible.sync="dialogVisible" width="55%" :before-close="handleClose">
			<el-form :model="editForm"  :rules="editFormRules" label-width="105px" ref="editForm">
				<el-form-item label="投诉人姓名" prop="realName">
					<el-input v-model="editForm.realName" auto-complete="off" placeholder="投诉人姓名" disabled></el-input>
				</el-form-item>
				<el-form-item label="投诉人手机号" prop="phone">
					<el-input v-model="editForm.phone" auto-complete="off" placeholder="投诉人手机号" disabled></el-input>
				</el-form-item>
				<el-form-item label="投诉内容" prop="problem">
					<el-input v-model="editForm.problem" auto-complete="off" placeholder="投诉内容" disabled></el-input>
				</el-form-item>
				<el-form-item label="处理意见" prop="disposeContent">
					<el-input v-model="editForm.disposeContent" auto-complete="off" placeholder="请输入处理意见"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary"  @click.native="editSubmit"  :loading="loading">确定</el-button>
			</span>
		</el-dialog>
		<!-- 查看内容 -->
		<el-dialog title="查看投诉内容" :visible.sync="examinevisible" width="55%" style="margin-top: -80px;">
			<el-form label-width="105px">
				<el-form-item label="投诉人姓名" prop="realName">
					<el-input v-model="seelist.realName" auto-complete="off" placeholder="投诉人姓名" readonly></el-input>
				</el-form-item>
				<el-form-item label="投诉人手机号" prop="phone">
					<el-input v-model="seelist.phone" auto-complete="off" placeholder="投诉人手机号" readonly></el-input>
				</el-form-item>
				<el-form-item label="投诉类型" prop="problemType">
					<el-input v-if="seelist.problemType == '1'" v-model="this.Type1" auto-complete="off" placeholder="投诉类型" readonly></el-input>
					<el-input v-if="seelist.problemType == '2'" v-model="this.Type2" auto-complete="off" placeholder="投诉类型" readonly></el-input>
				</el-form-item>
				<el-form-item label="投诉商品名称" prop="goodsName">
					<el-input v-model="seelist.goodsName" auto-complete="off" placeholder="投诉商品名称" readonly></el-input>
				</el-form-item>
				<el-form-item v-if="seelist.problemType == '1'" label="投诉商品ID" prop="goodsId">
					<el-input v-model="seelist.goodsId" auto-complete="off" placeholder="投诉商品ID" readonly></el-input>
				</el-form-item>
				<el-form-item v-else-if="seelist.problemType == '2'" label="投诉订单ID" prop="orderId">
					<el-input v-model="seelist.orderId" auto-complete="off" placeholder="投诉订单ID" readonly></el-input>
				</el-form-item>
				<el-form-item label="投诉项目" prop="problem">
					<el-input v-model="seelist.problem" auto-complete="off" placeholder="投诉项目" readonly></el-input>
				</el-form-item>
				<el-form-item label="投诉内容" prop="problemContent">
					<el-input v-model="seelist.problemContent" auto-complete="off" placeholder="投诉内容" readonly></el-input>
				</el-form-item>
				<el-form-item label="处理人姓名">
					<el-input  v-if="seelist.disposeName != ''" v-model="seelist.disposeName" auto-complete="off" placeholder="处理人姓名" readonly></el-input>
					<el-input  v-else v-model="this.Name" auto-complete="off" placeholder="处理人姓名" readonly></el-input>
				</el-form-item>
				<el-form-item label="处理内容" prop="disposeContent">
					<el-input v-model="seelist.disposeContent" auto-complete="off" placeholder="处理内容" readonly></el-input>
				</el-form-item>
				<el-form-item label="投诉时间" prop="createTime">
					<el-input v-model="seelist.createTime" auto-complete="off" placeholder="投诉时间" readonly></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="examinevisible = false">取 消</el-button>
				<el-button v-if="seelist.problemType == '1'" type="primary"  @click="detailSubmit(seelist.goodsId)"  :loading="loading">查看投诉商品详情</el-button>
				<el-button v-else-if="seelist.problemType == '2'" type="primary"  @click="detailSubmit(seelist.orderId)"  :loading="loading">查看投诉订单详情</el-button>
			</span>
		</el-dialog>
	</section>
</template>
<script>
	import {
		getProblem,
		editProblem,
		Refreshtoken
	} from '../../../api/api';

	export default {
		data() {
			return {
				loading: false,
				List: [],
				type:0,
				total: 0,
				page: 1,
				size:10,
				sels: [],//列表选中列
				timer: null,
				dialogVisible:false,
				editForm:{
					disposeContent:''
				},
				editFormRules:{
					disposeContent: [{
						required: true,
						message: '请输入处理意见',
						trigger: 'blur'
					}],
				},
				examinevisible:false,
				seelist:{},
				Type1:'商品',
				Type2:'订单',
				Name:'系统管理员'
			}
		},
		mounted() {
			var Token = sessionStorage.getItem('Token');
			var timestamp=new Date().getTime();
			let para = {
				token: Token,
				curpage:this.page,
				pagesize:this.size,
				timestamp: timestamp
			};
			this.loading = true;
			getProblem(para).then((res) => {
				var res = res.data;
				if (res.code != 0) {
					this.$message({
						message: res.message,
						type: 'error'
					});
				} else {
					this.total = res.data.total;
					this.List = res.data.list;
					this.loading = false;
				}
			});
			
			this.queryInfo();
			this.timer = setInterval(() => {
			   setTimeout(this.queryInfo, 0)
		    }, 600000)
			
		},
		methods: {
			detailSubmit(id){
				this.$notify.info({
				  title: '提醒',
				  message: '该模块正在开发，敬请期待'
				});
			},
			getsee(index,row){
				this.examinevisible = true
				this.seelist = this.List[index]
			},
			// 类型转换
			Type: function (row, column) {
				return row.problemType == 1 ? '商品' : row.problemType == 2 ? '订单' : '未知';
			},
			// 设置定时器
			queryInfo() {
				var Token = sessionStorage.getItem('Token');
				var timestamp=new Date().getTime();
				let para = {token: Token,timestamp: timestamp};
				Refreshtoken(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.loading = false;
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			//tab表格样式
			cellStyle({row, column}){
				return 'text-align:center;padding:10px;';
			},
			rowClass({row, column}){
				return 'text-align:center';
			},
			handleSizeChange(val) {
				this.size = val;
				this.Problemy();
			},
			handleCurrentChange(currentPage) {
				this.page = currentPage;
				this.Problemy();
			},
			// 关闭按钮
			handleClose(done) {
				this.$confirm('检测到未保存的内容，是否在离开页面前保存修改？', '确认信息', {
				          distinguishCancelAndClose: true,
				          confirmButtonText: '保存',
				          cancelButtonText: '放弃修改'
				        })
					.then(_ => {
						done();
					})
					.catch(_ => {});
			},
			// 投诉处理
			handleEdit(index, row) {
				this.dialogVisible = true;
				this.editForm = Object.assign({}, row);
			},
			editSubmit(){
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认修改审核状态吗？', '提示', {}).then(() => {
							this.loading = true;
							var Token = sessionStorage.getItem('Token');
							var timestamp = new Date().getTime();
							let para = {
								token: Token,
								timestamp: timestamp,
								disposeContent: this.editForm.disposeContent,
								id:this.editForm.id
							};
							editProblem(para).then((res) => {
								var res = res.data;
								if (res.code != 0) {
									this.$message({
										message: res.message,
										type: 'error'
									});
								}else{
									this.loading = false;
									this.$message({
										message: '提交成功',
										type: 'success'
									});
									this.$refs['editForm'].resetFields();
									this.dialogVisible = false;
									this.Problemy();
								}
							});
						});
					}
				});
			},
			Problemy:function(){
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				let para = {
					token: Token,
					curpage:this.page,
					pagesize:this.size,
					timestamp: timestamp
				};
				this.loading = true;
				getProblem(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.total = res.data.total;
						this.List = res.data.list;
						this.loading = false;
					}
				});
			}
		},
		beforeDestroy() {
		  clearInterval(this.timer);        
		  this.timer = null;
		}
	};
</script>

<style scoped>
.el-button.is-disabled{
	color: #bfcbd9;
	    cursor: not-allowed;
	    background-image: none;
	    background-color: #eef1f6;
	    border-color: #d1dbe5;
}
.el-pagination {
    white-space: nowrap;
    padding: 2px 5px;
    color: #48576a;
}
.demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>
